

for(sw in 1:1080){
fname <- paste("/home/rumen/simulation/sim",sw,"/sim",sw,".frequencies",sep="")
data <- read.csv(fname, header=FALSE)

# days of simulation 182..7300
days <- unique(data[,2])
clones.log <- NULL
for(i in 1:length(days)){
    log <- data[data[,2]==days[i],]
    repr.clones <- length(log[log[,4]>=105&log[,4]<=109,1])
    surv.clones <- length(log[log[,4]>=100&log[,4]<=104,1])
    neut.clones <- length(log[log[,4]<=99,1])
    combined.freq.repr.clones <- sum(log[log[,4]>=105&log[,4]<=109,3])
    combined.freq.surv.clones <- sum(log[log[,4]>=100&log[,4]<=104,3])
    combined.freq.neut.clones <- sum(log[log[,4]<=99,3])
    clones.log <- rbind(clones.log,cbind(days[i],log[1,5],repr.clones,surv.clones,neut.clones,combined.freq.repr.clones,combined.freq.surv.clones,combined.freq.neut.clones))    
}
colnames(clones.log)[1:2] <- c("day","generation")
write.table(clones.log,file=paste("clones.number.alleles.frequency.analysis/sim",sw,".clones.number.csv",sep=""),col.names=FALSE,row.names=FALSE,quote=FALSE,sep=",")

# alleles analysis
alleles.log <- NULL
for(i in 1:length(days)){
    log <- data[data[,2]==days[i],]
    allele.freq <- rep(0,109)
    for(j in 1:109){
	# sum of all clone frequencies that have this allele hit
	allele.freq[j] <- sum(log[log[,4]==j,3])
    }
    alleles.log <- rbind(alleles.log,cbind(days[i],log[1,5],t(allele.freq)))
}
write.table(alleles.log,file=paste("clones.number.alleles.frequency.analysis/sim",sw,".alleles.frequencies.csv",sep=""),col.names=FALSE,row.names=FALSE,quote=FALSE,sep=",")

}
